﻿<style>
    .spantk {
        margin-top: 8px;
        width: 320px !important;
    }
</style>
<div class="layui-form" lay-filter="layuiadmin-app-form-list" id="layuiadmin-app-form-list" style="padding: 20px -30px 0 0;">

    <script type='text/html' template lay-done='layui.data.formdone(d.params);'>
        <input type='hidden' name='PID' value="{{ d.params.PID || '' }}" />
    </script>
    <fieldset class="layui-elem-field layui-field-title">
        <legend>审核信息</legend>
    </fieldset>
    <div class='layui-form-item'>
        <label class='layui-form-label'>审核状态</label>
        <div class='layui-input-inline spantk'>
            <script type='text/html' template>
                <span style="color:red;font-weight:bold;font-size:1.1em" id="spState">--</span>
            </script>
        </div>
        <label class='layui-form-label'>审核原因</label>
        <div class='layui-input-inline spantk'>
            <script type='text/html' template>
                <span>{{ d.params.AuditResult || '' }}</span>
            </script>
        </div>
    </div>
    <div class='layui-form-item'>
        <label class='layui-form-label'>审核人</label>
        <div class='layui-input-inline spantk'>
            <script type='text/html' template>
                <span>{{ d.params.AuditUserName || '' }}</span>
            </script>
        </div>
        <label class='layui-form-label'>审核时间</label>
        <div class='layui-input-inline spantk'>
            <script type='text/html' template>
                <span>{{ d.params.AuditTime || '' }}</span>
            </script>
        </div>
    </div>
    <div class='layui-form-item' id="divResult" style="display:none">
        <label class='layui-form-label'>退款结果</label>
        <div class='layui-input-inline spantk' style="width:80%">
            <script type='text/html' template>
                <span style="color:red;font-size:1.1em" id="spResult">--</span>
            </script>
        </div>
    </div>
    <fieldset class="layui-elem-field layui-field-title">
        <legend>申请信息</legend>
    </fieldset>
    <div class='layui-form-item'>
        <label class='layui-form-label'>退款单号</label>
        <div class='layui-input-inline spantk'>
            <script type='text/html' template>
                <span>{{ d.params.Code || '' }}</span>
            </script>
        </div>
        <label class='layui-form-label'>订单号</label>
        <div class='layui-input-inline spantk'>
            <script type='text/html' template>
                <span>{{ d.params.OrderNumber || '' }}</span>
            </script>
        </div>
    </div>
    <div class='layui-form-item'>
        <label class='layui-form-label'>退款金额</label>
        <div class='layui-input-inline spantk'>
            <script type='text/html' template>
                <span style="color:#FF5722">￥</span>
                <span style="font-weight:bold;font-size:1.4em;color:#FF5722">{{ d.params.ReturnPrice || '' }}</span>
            </script>
        </div>
        <label class='layui-form-label'>退款类型</label>
        <div class='layui-input-inline spantk'>
            <script type='text/html' template>
                <span id="spReturnType" style="font-weight:bold"></span>
            </script>
        </div>
    </div>
    <div id="divgood" style="display:none">
        <div class='layui-form-item'>
            <label class='layui-form-label'>申请商品</label>
            <div class='layui-input-inline spantk'>
                <script type='text/html' template>
                    <span style="font-weight:bold">{{ d.params.Name || '' }}</span>
                </script>
            </div>
            <label class='layui-form-label'>申请数量</label>
            <div class='layui-input-inline spantk'>
                <script type='text/html' template>
                    x
                    <span style="font-weight:bold;font-size:1.2em">{{ d.params.Num || '' }}</span>
                </script>
            </div>
        </div>
        <div class='layui-form-item'>
            <label class='layui-form-label'>申请商品订单总额</label>
            <div class='layui-input-inline spantk'>
                <span style="color:#FF5722">￥</span>
                <span style="font-weight:bold;font-size:1.2em;color:#FF5722" id="spOrderGoodAmount">--</span>
            </div>
            <label class='layui-form-label'>申请商品下单数量</label>
            <div class='layui-input-inline spantk'>
                <script type='text/html' template>
                    x
                    <span style="font-weight:bold;font-size:1.2em" id="spOrderGoodNum">--</span>
                </script>
            </div>
        </div>
    </div>
    <div>
        <div class='layui-form-item'>
            <label class='layui-form-label'>订单实付金额</label>
            <div class='layui-input-inline spantk'>
                <span style="color:#FF5722">￥</span>
                <span style="font-weight:bold;font-size:1.2em;color:#FF5722" id="spOrderPayPrice">--</span>
            </div>
            <label class='layui-form-label'>订单当前状态</label>
            <div class='layui-input-inline spantk'>
                <script type='text/html' template>
                    <span style="font-weight:bold;color:#1E9FFF" id="spOrderState">--</span>
                </script>
            </div>
        </div>
    </div>
    <div class='layui-form-item'>
        <label class='layui-form-label'>退货方式</label>
        <div class='layui-input-inline spantk'>
            <script type='text/html' template>
                <span id="spReturnMode" style="font-weight:bold"></span>
            </script>
        </div>
        <label class='layui-form-label'>申请原因</label>
        <div class='layui-input-inline spantk'>
            <script type='text/html' template>
                <span style="font-weight:bold;">{{ d.params.Reason || '' }}</span>
            </script>
        </div>
    </div>
    <div id="divdesc" style="display:none">
        <div class='layui-form-item'>
            <label class='layui-form-label'>问题描述</label>
            <div class='layui-input-inline spantk' style="width:80%">
                <script type='text/html' template>
                    <span>{{ d.params.Descption || '' }}</span>
                </script>
            </div>
        </div>
        <div class='layui-form-item'>
            <label class='layui-form-label'>图片描述</label>
            <div class='layui-input-inline' spantk style="width:80%">
                <div class="layui-upload">
                    <div class="layui-upload-list" id="divImgs"></div>
                    <script type='text/html' template lay-done='layui.data.setUploads(d.params);'>
                        <input type="hidden" name="Images" id="Images" value="{{ d.params.Images || '' }}">
                    </script>
                    <hr />
                </div>
            </div>
        </div>
    </div>
    <div class='layui-form-item'>
        <label class='layui-form-label'>申请人</label>
        <div class='layui-input-inline spantk'>
            <script type='text/html' template>
                <span>{{ d.params.ApplyUserName || '' }}</span>
                <span>(会员编号：{{ d.params.MemberCode || '' }})</span>
            </script>
        </div>
        <label class='layui-form-label'>申请时间</label>
        <div class='layui-input-inline spantk'>
            <script type='text/html' template>
                <span>{{ d.params.ApplyTime || '' }}</span>
            </script>
        </div>
    </div>
    <div class='layui-form-item'>
        <label class='layui-form-label'>联系人</label>
        <div class='layui-input-inline spantk'>
            <script type='text/html' template>
                <span>{{ d.params.UserName || '' }}</span>
            </script>
        </div>
        <label class='layui-form-label'>联系电话</label>
        <div class='layui-input-inline spantk'>
            <script type='text/html' template>
                <span>{{ d.params.UserTel || '' }}</span>
            </script>
        </div>
    </div>
</div>
<style>
    .layui-upload-img {
        width: 100px;
        height: auto;
        margin-left: 3px;
    }
</style>

<script type="text/javascript">

    layui.use(['form'], function () {
        var form = layui.form;//required（必填项）phone（手机号）email（邮箱）url（网址）number（数字）date（日期）identity（身份证） 自定义值
    });


    layui.data.formdone = function (d) {
        var form = layui.form;
        var admin = layui.admin;
        var $ = layui.$;

        if (d.State == 0) {
            $("#spState").text("申请中");
        } else if (d.State == 1) {
            $("#spState").text("同意退款");
        } else if (d.State == 2) {
            $("#spState").text("拒绝退款");
        } else {
            $("#spState").text("取消");
        }

        $("#divResult").hide();
        if (d.State == 1) {
            var rs = "";
            if (d.RefundResult == 1) {
                rs = "退款成功";
            } else if (d.RefundResult == 2) {
                rs = "退款失败";
            } else {
                rs = "正在退款";
            }
            if (d.RefundResultNote != "" && d.RefundResultNote != null) {
                rs += " (" + d.RefundResultNote + ")";
            }
            $("#spResult").text(rs);
            $("#divResult").show();
        }

        if (d.ReturnType == 0) {
            $("#spReturnType").text("商品退款");
        } else {
            $("#spReturnType").text("整单退款");
        }
        if (d.ReturnMode == 1) {
            $("#spReturnMode").text("快递寄回");
        } else if (d.ReturnMode == 2) {
            $("#spReturnMode").text("送回店铺");
        } else {
            $("#spReturnMode").text("无需退货");
        }

        Loaddiv(d);

    }

    function Loaddiv(d) {
        var form = layui.form;
        var admin = layui.admin;
        var $ = layui.$;


        admin.req({
            url: layui.setter.APIUrl + '/shop/orderMgr/getModel?key='+d.OrderID
          , type: "post"
          , done: function (res) {
              var order = res.Data.data[0];
              if (order != null && order != undefined) {
                  $("#spOrderPayPrice").text(order.PayPrice);
                  $("#spOrderState").text(order.StateName);
              }

          }
        });

        if (d.ReturnType == 0) {
            $("#divgood").show();
            $("#divdesc").show();

            admin.req({
                url: layui.setter.APIUrl + '/shop/order_goodsMgr/getModel?OrderID=' + d.OrderID + "&GoodID="+d.GoodID
              , type: "post"
              , done: function (res) {
                  var orderGood = res.Data;
                  if (orderGood != null && orderGood != undefined) {
                      $("#spOrderGoodAmount").text(orderGood.AllPrice);
                      $("#spOrderGoodNum").text(orderGood.Count);
                  }

              }
            });

        } else {
            $("#divgood").hide();
            $("#divdesc").hide();
        }
    }


    layui.data.setUploads = function (d) {
        layui.use(['jquery', 'upload', 'admin'], function () {
            window.jQuery = window.$ = layui.jquery;
            upload = layui.upload,
                admin = layui.admin;

            var pics = d.Images;
            if (pics != "" && pics != null && pics != 'null') {
                var strs = JSON.parse(pics);
                for (var i = 0; i < strs.length; i++) {
                    var str = strs[i];
                    if (str != "") {
                        if (str.indexOf("http") >= 0) {
                            addImg({ name: str, path: str });
                        } else {
                            addImg({ name: str, path: layui.setter.ImgPath + str });
                        }
                    }
                }
            }
        })
    }
    function addImg(src) {
        var html = "    <div style=\"line-height:100px;float:left\"> " +
                           " <img src=\"" + src.path + "\"   alt=\"\" class=\"layui-upload-img\">" +
                       "</div>";
        $('#divImgs').append(html);
    }

    layui.data.datedone = function (d) {
        layui.use(['laydate'], function () {
                var laydate = layui.laydate;

            //日期时间选择器
            laydate.render({
                elem: '#ApplyTime'
              , type: 'datetime'
              , calendar: true
            });
            laydate.val = d.ApplyTime;

            //日期时间选择器
            laydate.render({
                elem: '#AuditTime'
              , type: 'datetime'
              , calendar: true
            });
            laydate.val = d.AuditTime;

        });
    }
</script>
